const jwt = require('jsonwebtoken')
const { expressjwt } = require('express-jwt')
const secretKey = "heike233 owo"
class Token {
    /**
     * 使用json获取一个持续3600s的token
     * @param {用户名和密码组成的json} json 
     * @returns 
     */
    static getToken(id,username, isSuper,rule) {
        let json = {id:id,username: username, super: isSuper,rule:rule}
        return jwt.sign(json, secretKey, { expiresIn: '10h' })//一小时
    }
    static getuseToken() {
        return expressjwt({ secret: secretKey, algorithms: ['HS256'] })
    }
}
module.exports = Token